const app = getApp();
const utils = require('../../utils/pay.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    payUid: null,//代支付人编号
    userInfo: {},
    userInfo2:{},
    payByUid:null,//推荐人编号
    isShowInfo:false//是否显示代好友支付信息
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },
 

  bindinputUid: function(e) {
    this.setData({
      payUid: e.detail.value
    })
  },
  bindinputByUid: function (e) {
    this.setData({
      payByUid: e.detail.value
    })
  },
  cardPayOrder: function() {
    this.getUserInfo()
  },
  backInput:function(){
    this.setData({ isShowInfo: false })
  },
  //提交支付
  submitCreateStaffOrder: function() {
    let that = this;
    wx.showLoading({
      title: '提交中',
      mask: true
    })
    wx.request({
      url: app.globalData.host + '/api/Order/SubmitCreateStaffOrder',
      data: {
        uid: that.data.payUid,//代支付人
        shareStaffId: 0,//推荐人
        shareUid: that.data.payByUid//当前人
      },
      method: 'POST',
      success: function(res) {
        wx.hideLoading();
        if (res.data.Code == 0) {
          utils.wxpay(app, res.data.Data, 1)
          that.setData({ isShowInfo: false })
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.Message,
            showCancel: false,
          })
          return;
        }
      },
      fail: function(err) {
        wx.showModal({
          title: '提示',
          content: res.data.Message,
          showCancel: false,
        })
        return;
      }
    })
  },

  //获取用户信息
  getUserInfo: function() {
    let that = this;
    if (!that.data.payUid) {
      wx.showModal({
        title: '提示',
        content: '请输入好友ID',
        showCancel: false,
      })
      return;
    }
    if (!that.data.payByUid) {
      wx.showModal({
        title: '提示',
        content: '请输入推荐人ID',
        showCancel: false,
      })
      return;
    }
    that.getFriendInfo(1)
    that.getFriendInfo(2)
  },

  //获取代支付信息
  getFriendInfo:function(id){
    let that = this;
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    let uid = 0;
    if(id == 1){
      uid = that.data.payUid
    }else{
      uid = that.data.payByUid
    }
    wx.request({
      url: app.globalData.host + '/api/User/GetUserInfo?uid=' + uid,
      success: function (res) {
        wx.hideLoading();
        if (res.data.Code == 0) {
          if(id == 1){
            that.setData({
              userInfo: res.data.Data.UserInfo,
              isShowInfo: true
            })
          }else{
            that.setData({
              userInfo2: res.data.Data.UserInfo,
              isShowInfo: true
            })
          }
        } else {
          that.setData({ isShowInfo: false })
          wx.showModal({
            title: '提示',
            content: res.data.Message,
            showCancel: false,
          })
          return;
        }
      }
    })
  }


})